package org.ade.monak.anak.service.gate.monak;

import org.ade.monak.anak.entity.DataMonitoring;
import org.ade.monak.anak.entity.Ortu;
import org.ade.monak.anak.service.DatabaseThreadService;
import org.ade.monak.anak.service.storage.DatabaseManagerAnak;
import org.ade.monak.anak.service.storage.LogMonakFileManager;

import android.content.Context;
import android.os.Handler;

public class ReceiverStartMonitoring {
	public ReceiverStartMonitoring(Context context, DatabaseThreadService databaseThread, Ortu ortu){
		this.databaseThread	= databaseThread;
		this.context 		= context;
		this.ortu			= ortu;
	}
	
	public void startMonitoring(final String idMonitoring){
		final Handler handler = new Handler();
		databaseThread.addDatabaseThread(new Runnable() {
			public void run() {
				DatabaseManagerAnak databaseManager = new DatabaseManagerAnak(context);
				DataMonitoring dataMonitoring = databaseManager.getDataMonitoringByIdMonitoringAndOrtu(idMonitoring,ortu.getIdOrtu(), false, false);

				if(dataMonitoring!=null){
					dataMonitoring.setAktif(true);
					databaseManager.setAktifMonitoring(dataMonitoring);	
					handler.post(new Runnable(){
						public void run() {
							SenderKonfirmasi sender = new SenderKonfirmasi(context,ortu);
							sender.sendKonformasiAktifMonitoring(idMonitoring);		
						}
						
					});
				}
				
			}
		});
		
		
	}
	
	private final DatabaseThreadService databaseThread;
	private final Context 	context;
	private final Ortu 		ortu;
}
